package com.lvtu.monitor.shiro.dao;

import com.lvmama.com.lvtu.common.utils.MemcachedUtil;

/** 
 * @Title: CacheHelper.java 
 * @Package com.lvtu.monitor.shiro.dao 
 * @Description: 缓存帮助类 
 * @author lvzimin 
 * @date 2015年6月10日 下午8:53:48 
 * @version V1.0.0 
 */
public class CacheHelper {
	
	private final static String SHIRO_CACHE_KEY_PREFIX = "lvtu_monitor_"; 

	public enum CacheType {
		user, 		// 用户
		role, 		// 角色
		resource 	// 资源
	}
	
	public static void setCache(CacheHelper.CacheType cacheType, Object id, Object obj) {
		String key = SHIRO_CACHE_KEY_PREFIX + cacheType.name() + "_" + id;
		MemcachedUtil.getInstance().set(key, obj);
	}
	
	public static void cleanCache(CacheHelper.CacheType cacheType, Object id) {
		String key = SHIRO_CACHE_KEY_PREFIX + cacheType.name() + "_" + id;
		MemcachedUtil.getInstance().remove(key);
	}
	
	public static Object getCache(CacheHelper.CacheType cacheType, Object id) {
		String key = SHIRO_CACHE_KEY_PREFIX + cacheType.name() + "_" + id;
		return MemcachedUtil.getInstance().get(key);
	}
	
}
